package com.smallcr.exception;

import org.apache.commons.lang3.StringUtils;
import org.springframework.ui.ModelMap;

import com.smallcr.constant.HttpStatusEnum;

public abstract class BaseException extends RuntimeException {

	private static final long serialVersionUID = 1L;

	public BaseException() {
	}

	public BaseException(Throwable ex) {
		super(ex);
	}

	public BaseException(String message) {
		super(message);
	}

	public BaseException(String message, Throwable ex) {
		super(message, ex);
	}

	public void handler(ModelMap modelMap) {
		modelMap.put("code", getStatus().getCode());
		if (StringUtils.isNotBlank(getMessage())) {
			modelMap.put("msg", getMessage());
		} else {
			modelMap.put("msg", getStatus().getCode());
		}
		modelMap.put("timestamp", System.currentTimeMillis());
	}

	protected abstract HttpStatusEnum getStatus();

}
